﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data.Entity.ModelConfiguration;
using System.ComponentModel.DataAnnotations.Schema;

namespace MealCardManagement.Data.Mapping
{
    class MealCardConfig : EntityTypeConfiguration<MealCard>
    {
        public MealCardConfig()
        {
            ToTable("MealCard");

            HasKey(x => x.Id);

            Property(x => x.Id)
                .HasDatabaseGeneratedOption(DatabaseGeneratedOption.Identity);

            Property(x => x.CreatTime)
                .IsRequired();

            Property(x => x.Money)
                .HasPrecision(12, 2)
                .IsRequired();

            HasRequired(x => x.Owner)
                .WithMany(x => x.MealCards)
                .Map(m => m.MapKey("OwnerId"))
                .WillCascadeOnDelete();
        }
    }
}
